import HDataTable from "@/components/ant-ext-table/HDataTable";
import HTag from "@/components/ant-ext/HTag";
import {ContractType, PaymentStat} from "@/const/const";
import {Form} from "antd";
import React from "react";
import {Dispatch} from "redux";
import {HTableProps} from "@/components/ant-ext-table/HTable";
import {useDispatch} from "react-redux";
import EntityPaymentTrade from "@/api/entity-payment-trade";

function getColumns(dispatch: Dispatch): HTableProps<any>["columns"] {
    return [
        {
            title: "订单号",
            dataIndex: 'tradeNo',
            width: '100px',
            fixed: 'left',
        }, {
            title: "合同订单号",
            dataIndex: 'contractNo',
        }, {
            title: "合同类型",
            dataIndex: 'contractType',
            render: (value: any) => <HTag value={value} mapping={ContractType.tag}/>
        }, {
            title: "债权人",
            dataIndex: 'hoName',
        }, {
            title: "债务人",
            dataIndex: 'coName',
        }, {
            title: "支付金额",
            dataIndex: 'amount',
        }, {
            title: "分润金额",
            dataIndex: 'shareProfit',
        }, {
            title: "订单描述",
            dataIndex: 'remark',
        }, {
            title: "支付描述",
            dataIndex: 'description',
        }, {
            title: "状态",
            dataIndex: 'stat',
            render: (value: any) => <HTag value={value} mapping={PaymentStat.tag}/>
        }, {
            title: "微信支付单号",
            dataIndex: 'wxTradeNo',
        }, {
            title: "创建时间",
            dataIndex: 'createTime',
        }, {
            title: "成功时间",
            dataIndex: 'successTime',
        }
    ]
}

export default function Trade() {
    const [form] = Form.useForm()
    const dispatch = useDispatch()

    return <>
        <HDataTable
            queryForm={{
                form: form,
                item: [
                    {name: "hoName", label: "债权人"},
                    {name: "coName", label: "债务人"},
                    {name: "stat", label: "状态", type: "select", dataSource: PaymentStat.select, width: "150px"},
                ]
            }}
            columns={getColumns(dispatch)} selectMethod={EntityPaymentTrade.selectTablePage}
            rowKey={EntityPaymentTrade.RowKey}
        />
    </>
}